package com.waldamartin.android.mobileapplicationspairsapp.control;

import com.waldamartin.android.mobileapplicationspairsapp.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.MotionEvent;
import android.widget.ImageView;

/**
 * Class to handle user input at splash screen.
 * 
 * @author Martin
 */
public class SplashFullScreenActivity extends Activity
{
	private ImageView ivFinger1;
	private ImageView ivFinger2;
	
	@Override
	protected void onCreate(Bundle savedInstanceState)
	{
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_splash_full_screen);
		ivFinger1 = (ImageView)findViewById(R.id.ivfinger1);
		ivFinger2 = (ImageView)findViewById(R.id.ivfinger2);
		
		ivFinger1.setVisibility(ImageView.INVISIBLE);
		ivFinger2.setVisibility(ImageView.INVISIBLE);
	}

	@Override
	public boolean onTouchEvent(MotionEvent motionEvent)
	{
		// Detect gestures
		switch(motionEvent.getPointerCount())
		{
			case 1 : // One finger
			{
				switch(motionEvent.getAction())
				{
					case MotionEvent.ACTION_DOWN : 
					{
						// Visualisation for user
						ivFinger1.setVisibility(ImageView.VISIBLE);
						break;
					}
					case MotionEvent.ACTION_MOVE : break;
					case MotionEvent.ACTION_UP : 
					{
						// Visualisation for user
						ivFinger1.setVisibility(ImageView.INVISIBLE);
						break;
					}	
				}
				break;
			}
			case 2 : // Two fingers
			{
				switch(motionEvent.getAction() & MotionEvent.ACTION_MASK)
				{
					case MotionEvent.ACTION_DOWN : break;
					case MotionEvent.ACTION_UP : break;
					case MotionEvent.ACTION_POINTER_DOWN :
					{
						// Debug
						System.out.println("Detected 2 fingers");
						
						// Visualisation for user
						ivFinger2.setVisibility(ImageView.VISIBLE);
							
						// Create new intent to start view for game selection
						Intent startGame = new Intent(SplashFullScreenActivity.this, GameListActivity.class);
						startGame.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	
						startActivity(startGame);
						this.finish(); // Prevent user to go back to splash screen
	
						break;
					}
					case MotionEvent.ACTION_POINTER_UP : break;
					case MotionEvent.ACTION_MOVE : break;
				}
				break;
			}
			default:
			{
				ivFinger1.setVisibility(ImageView.INVISIBLE);
				ivFinger2.setVisibility(ImageView.INVISIBLE);
				break;
			}
		} // switch(motionEvent.getPointerCount()) End
		return true;
	} // onTouchEvent End

}
